﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace System.CJL.Infrstructre
{
    public class MESRepository<T> : IMESRepository<T> where T : class
    {
        MESDbContext _context;
        public MESRepository(MESDbContext context)
        {
            _context=context;
        }

        public async Task<int> Addasync(T entity)
        {
            await _context.Set<T>().AddAsync(entity);
            return await  _context.SaveChangesAsync();
        }

        public async Task<int> DeleteAsync(int id)
        {
            var arr = await _context.Set<T>().FindAsync(id);
            _context.Remove(arr);
            return  await   _context.SaveChangesAsync();
        }

        public async Task<List<T>> GetAll()
        {
            return await _context.Set<T>().ToListAsync();
        }

        public async Task<T> GetMondel(int id)
        {
            return await _context.Set<T>().FindAsync(id);
        }

        public async Task<int> UpdateAsync(T entity)
        {
            _context.Set<T>().Update(entity);
            return await _context.SaveChangesAsync();
        }
    }
}
